package com.company.arithmetic;

import java.util.Scanner;

/**
 * Created by v on 16-11-29.
 */
public class Sudoku {
    private static int[][] map=new int[9][9];
    public static int max=-1;

    public static boolean[] find(int x,int y){
        boolean[] find=new boolean[10];
        for(int i=0;i<9;i++){
            find[map[x][i]]=true;
            find[map[i][y]]=true;
        }

        for(int i=x/3*3;i<x/3*3+3;i++){
            for(int j=y/3*3;j<y/3*3+3;j++){
                find[map[i][j]]=true;
            }
        }

        return find;
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
                map[i][j] = input.nextInt();
            }
        }
        calculate(0, 0);
        //System.out.println(max);
    }

    public static void calculate(int x,int y){
        if(x==9){
            int number=0;
            for(int i=0;i<5;i++){
                for(int j=i,k=i;j<9-i;j++){
                    number+=map[j][k]*(6+i);
                }
                for(int j=i,k=i+1;k<9-i;k++){
                    number+=map[j][k]*(6+i);
                }
                for(int j=i+1,k=9-i-1;j<9-i;j++){
                    number+=map[j][k]*(6+i);
                }
                for(int j=9-i-1,k=i+1;k<9-i-1;k++){
                    number+=map[j][k]*(6+i);
                }
            }
            if(number>max){
                max=number;
            }

            for(int i=0;i<9;i++){
                for(int j=0;j<9;j++){
                    System.out.print(map[i][j]+" ");
                }
                System.out.println();
            }
            System.out.println();
            return;
        }

        if(map[x][y]==0){
            boolean[] find=find(x,y);
            for(int i=1;i<find.length;i++){
                if(!find[i]){
                    map[x][y]=i;
                    if(y<8){
                        calculate(x,y+1);
                    }else {
                        calculate(x+1,0);
                    }
                }
            }
            map[x][y]=0;
            return;
        }

        if(y<8){
            calculate(x,y+1);
        }else {
            calculate(x+1,0);
        }
    }
}